<!--
 * @Author: GL
 * @Date: 2022-09-20 17:04:32
 * @LastEditors: GL
 * @LastEditTime: 2023-04-03 00:12:19
 * @Description: login
-->
<template>
  <div class="login">
    <el-form class="login-form" label-width="60px">
      <h3 class="title">轻麦后台管理系统</h3>
      <el-form-item label="用户名">
        <el-input
          v-model="loginData.name"
          type="text"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          v-model="loginData.passwd"
          type="password"
          placeholder="请输入密码"
          show-password
        ></el-input>
      </el-form-item>
      <el-button type="primary" size="default" class="btn" @click="login">登录</el-button>
      <p class="register" @click="register">还没有账号？</p>
    </el-form>
    <div class="copyRight">
      <div>@copyright2022-2023 最终解释权归轻麦（wqr）所有</div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import { userLogin } from "../network/user.js";
export default {
  name: "Home",
  data() {
    return {
      loginData: {
        name: "",
        passwd: "",
      },
    };
  },
  components: {},
  methods:{
    login() {
      userLogin(this.loginData.name,this.loginData.passwd).then((res) => {
        console.log(res);
        if (res.status == 0) {
          this.$message({
            message: res.msg,
            type: 'success'
          });
          window.sessionStorage.setItem('token',res.token) 
          if (window.sessionStorage.getItem('token')) {
            this.$router.replace('/home')
          }
        }else{
          this.$message({
            message: res.msg,
            type: 'warning'
          });
        }
        
      })
      .catch((err) => {
        console.log(err);
      })
      
    },
    register() {
      this.$router.push('/register')
    }
  }
};
</script>
<style lang="scss" scoped>
.login{
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/background.webp");
  background-size: cover;
  .login-form{
    background-color: #FFFFFF;
    border-radius: 6px;
    padding: 25px 25px 5px 25px;
    width: 25%;
    height: 40%;
    line-height: 48px;
    .title {
      margin: 0px auto 30px auto;
      text-align: center;
      color: #707070;
    }
    .btn{
      width: 100%;
    }
    .register{
      display: flex;
      justify-content: flex-end;
      font-size: 13px;
      color:  #79bbff;
    }
  }
  .copyRight{
    position: fixed;
    bottom: 5%;
  }
}
</style>
